<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../js/jquery.min.js"></script>
    <script src="../js/jquery.easyui.min.js"></script>
    <script src="../js/easyui-lang-zh_CN.js"></script>
    <link rel="stylesheet" href="../themes/icon.css">
    <link rel="stylesheet" href="../themes/default/easyui.css">
    <link rel="stylesheet" href="../css/wu.css">
    <style type="text/css">
        .subck { display:none }/*合计单元格样式*/
        .datagrid-row-selected{
		    background-color:none;
		}
    </style>
    <script>
        //显示流水列表
        function loadPartNo(code){
            $("#storageCode").val(code)
            var content="<iframe src='showPartNoList.jsp' frameborder='0'style='width: 100%;height: 100%'></iframe>";
            $("#list").dialog({
                content: content,
                title: '配件列表',
                width: 950,
                height: 440,
                closed: false,
                cache: false,
                modal: true,
            });
        }
	    //显示历次单价列表
        function loadPartPrice(code){
            var content="<iframe src='/kxmanage/part/showPartPriceList.html?code="+code+"' frameborder='0'style='width: 100%;height: 100%'></iframe>";
            $("#list").dialog({
                content: content,
                title: '配件列表',
                width: 650,
                height: 340,
                closed: false,
                cache: false,
                modal: true,
            });
        }
        var  selectIndex = -1;
        function getExcel(){
            $.messager.confirm('确认','您确认想要导出excel文件吗？（下载路径为浏览器默认下载路径）',function(r) {
                if (r) {
                    var options = $("#productList").datagrid("getPager").data("pagination").options;
					var curr = options.pageNumber;  
					var size = options.pageSize;
                     var findcode=$("#findcode").val();
                    var findstartDate=$("#findstartDate").val();
                    var findendDate=$("#findendDate").val();
                    var findsupplierName=$("#findsupplierName").val();
                    location.href="/kxmanage/instroageBill/getExcel.json?findcode="+findcode+"&findstartDate="+findstartDate
						+"&findendDate="+findendDate+"&findsupplierName="+findsupplierName+"&page="+curr+"&rows="+size; 
                }
            });
        }
        function hideTable(){
            $("#searchdiv").toggle();
        }
        function openaddinstroagebill(){
            self.parent.$("#jxc_tabs").tabs("close","增加入库单");
            self.parent.addTabs('增加入库单','goods/addInstroageBill.jsp');
        }
        
        function reloaddata(){
        	$("#form1").form('reset');
			$("#productList").datagrid('load',serializeJson());
        }
        
        $(function(){
             //添加下拉框
            $('#cc').combobox({    
			    url:'/kxmanage/instroageBill/getPartTypeList.json',    
			    valueField:'id',    
			    textField:'typeName'   
			});
            /* self.parent.$("#jxc_tabs").tabs({
                onSelect:function(title,index){
                    if(title=="入库单管理"){
                        $("#productList").datagrid("reload");
                    }
                }
            }) */
           	/* var data=$("#productList").datagrid('getData');
            alert('总数据量:'+data.total) */	
            //数据表格
            $("#productList").datagrid({
                url:'/kxmanage/part/getstorageinfolist.json',
                rownumbers:false,
                pageNumber:1,
                pageSize:5,
                pageList:[5,10,15],
                checkOnSelect:false,
                columns:[[
                    {field:'partNo',title:'件号',width:100,
                        formatter:function (value,row,index) {
                            if(row.isFooter){
                                return "";
                            }
                            var context="<a href=\"javascript:loadPartNo('"+row.code+"')\">"+row.partNo+"</a>&nbsp;&nbsp;" 
                            return context;
                        },
                        styler: function (value, row, index) {
                            if(row.isFooter){
                                return 'background-color:#F1F1F1';
                            }
                        }
                    },
                    {field:'currPartNo',title:'通用件号',width:80,
                        styler: function (value, row, index) {
                            if(row.isFooter){
                                return 'background-color:#F1F1F1';
                            }
                        }},
                    {field:'partName',title:'配件名称',width:200,
                        styler: function (value, row, index) {
                            if(row.isFooter){
                                return 'background-color:#F1F1F1';
                            }
                        }, formatter:function(value,row,index){
                            if(row.isFooter){
                                return row.partName;
                            }
                            return row.partName;
                    }},
                    {field:'mold',title:'配件型号',width:120,
                        styler: function (value, row, index) {
                            if(row.isFooter){
                                return 'background-color:#F1F1F1';
                            }
                        }, formatter:function(value,row,index){
                            if(row.isFooter){
                                return row.mold;
                            }
                            return row.mold;
                    }},
                    {field:'amount',title:'库存总量',width:80,
                        formatter:function(value,row,index){
                            if(row.isFooter){
                                return row.amount;
                            }
                            return row.amount;
                    },
                        styler: function (value, row, index) {
                            if(row.isFooter){
                                return 'background-color:#F1F1F1';
                            }
                        }
                    },
                    {field:'sellPrice',title:'销售价格(￥)',width:100,
                        formatter:function(value,row,index){
                            if(row.isFooter){
                                return row.sellPrice;
                            }
                            return row.sellPrice;
                        },
                        styler: function (value, row, index) {
                            if(row.isFooter){
                                return 'background-color:#F1F1F1';
                            }
                        }
                    },
                    {field:'opt',width:40,formatter:function (value,row,index) {
                            if(row.isFooter){
                                return "";
                            }
                            var context="<a href=\"javascript:loadPartPrice('"+row.code+"')\">...</a>&nbsp;&nbsp;" 
                            return context;
                        },
                        styler: function (value, row, index) {
                            if(row.isFooter){
                                return 'background-color:#F1F1F1';
                            }
                        }},
                    {field:'moneys',title:'库存总额(￥)',width:100,
                        formatter:function(value,row,index){
                            if(row.isFooter){
                                return row.moneys;
                            }
                            return (row.stroragePrice*row.amount).toFixed(2);;
                        },
                        styler: function (value, row, index) {
                            if(row.isFooter){
                                return 'background-color:#F1F1F1';
                            }
                        }
                    },
                    {field:'memo',title:'备注',width:160,
                        formatter:function(value,row,index){
                            if(row.isFooter){
                                return "";
                            }
                            return row.memo;
                        },
                        styler: function (value, row, index) {
                            if(row.isFooter){
                                return 'background-color:#F1F1F1';
                            }
                        }
                    },
                    {field:'alertAmount',title:'库存预警',width:60,
                        formatter:function(value,row,index){
                            if(row.isFooter){
                                return "";
                            }
                            if(row.amount<10){
                                return "缺货";
                            }else{
                                return "正常";
                            }
                        },
                        styler: function (value, row, index) {
                            if(row.isFooter){
                                return 'background-color:#F1F1F1';
                            }
                            if(row.amount<10){
                                return "color:red";
                            }
                        }
                    }
                ]],
                toolbar:'#wu_toolbar',
                showFooter:true,
                pagination:true ,//向后台传递参数page 和rows
                onClickRow: function(index, data) {
                    //$(this).datagrid('usw', index);
                },
                onLoadSuccess:function(data){
                    /* $('#productList').datagrid('appendRow', {
	                customName: '<span class="subtotal">合计</span>',
	                bamount: '<span class="subtotal">' + compute("bamount") + '</span>',
	                money: '<span class="subtotal">' + compute("money") + '</span>',
	                //Rate: '<span class="subtotal">' + ((compute("TotalOrderScore") / compute("TotalTrailCount")) * 100).toFixed(2) + '</span>'
                    }); */
                },
                 rowStyler: function (index, row) {
	                var rows = $("#productList").datagrid("selectRow"); 
	                if (rows) {
	                    return 'background-color:#ffffff;';
	                } else {
	                    return 'background-color:#ffffff;';
	                }
	            }
            })
            
        $("#search_btn").click(function(){
            $("#productList").datagrid('load',serializeJson())
        }) 
        });
        function detail(id) {
            $.messager.alert("信息","查看"+id+"产品详情");
        }
        function modifyInstroageBill(code) {
            self.parent.$("#jxc_tabs").tabs("close","修改入库单");
            parent.addTabs("修改入库单","../instroageBill/modifyInstroageBill.html?code="+code);
        }
        function addProduct() {
            parent.addTabs("添加产品","goods/add_goods.html");
        }
       
        
       //表单序列化
        function serializeJson(){  
            var serializeObj={};  
            var array=$("#form1").serializeArray();  
            var str=$("#form1").serialize();  
            $(array).each(function(){  
                if(serializeObj[this.name]){  
                    if($.isArray(serializeObj[this.name])){  
                        serializeObj[this.name].push(this.value);  
                    }else{  
                        serializeObj[this.name]=[serializeObj[this.name],this.value];
                    }  
                }else{  
                    serializeObj[this.name]=this.value;   
                }  
            });  
                return serializeObj;  
            }; 
        //指定列求和
        function compute(colName) {
			var rows = $('#productList').datagrid('getRows');
			var total = 0;
			for (var i = 0; i < rows.length; i++) {
				total += parseFloat(rows[i][colName]);
			}
			return total;
		}
		function onLoadSuccess() {
			//添加“合计”列
			$('#table').datagrid('appendRow', {
				Saler: '<span class="subtotal">合计</span>',
				TotalOrderCount: '<span class="subtotal">' + compute("TotalOrderCount") + '</span>',
				TotalOrderMoney: '<span class="subtotal">' + compute("TotalOrderMoney") + '</span>',
				TotalOrderScore: '<span class="subtotal">' + compute("TotalOrderScore") + '</span>',
				TotalTrailCount: '<span class="subtotal">' + compute("TotalTrailCount") + '</span>',
				Rate: '<span class="subtotal">' + ((compute("TotalOrderScore") / compute("TotalTrailCount")) * 100).toFixed(2) + '</span>'
			});
		}
    </script>
</head>
<body>
<div id="wu_toolbar">
    <div class="wu_toolbar_button" style="background-color:#CEDFEF;">
        <a  href="#" onclick="hideTable()" class="easyui-linkbutton" data-options="iconCls:'icon-search'" plain="true"> 查询</a>|
        <a  href="#"  class="easyui-linkbutton" data-options="iconCls:'icon-communication'" onclick="getExcel()" plain="true"> 导出excal</a>
    </div>
    <div id="searchdiv" style="display: block;width: 100%;">
        <form name="form1" id="form1">
            <table width="100%" border="0" cellspacing="0" style="background-color:#C9DFFF;border-top:1px solid white;" >
                <tbody><tr>
                    <td width="70"><b>检索条件:<input type="hidden" id="storageCode" value=""/></b></td>
                    <td width="70" align="right">件号:</td>
                    <td width="70" align="left"><input name="partNo" class="easyui-textbox" type="text" id="findcode" value="" maxlength="100"></td>
                    <td width="70" align="right">通用件号:</td>
                    <td width="70" align="left"><div class="l-text-wrapper"><div><input name="currPartNo" type="text" id="findstartDate" value="" maxlength="30" class="easyui-datebox" ligeruiid="findstartDate"><div class="l-text-l"></div><div class="l-text-r"></div><div class="l-trigger"><div class="l-trigger-icon"></div></div></div></div></td>
                    <td width="70" align="right">配件名称:</td>
                    <td width="70" align="left"><div class="l-text-wrapper"><div><input name="partName" type="text" id="findendDate" value="" maxlength="30" class="easyui-datebox" ligeruiid="findendDate"><div class="l-text-l"></div><div class="l-text-r"></div><div class="l-trigger"><div class="l-trigger-icon"></div></div></div></div></td>
                    <td width="70" align="right">配件品牌:</td>
                    <td width="70" align="left">
                         <select id="cc" class="easyui-combobox" name="partTypeId" style="width:120px;height:25px;">   
						      
						 </select>
                    </td>
                    <td width="70" align="right">库存状态:</td>
                    <td width="70" align="left">
                         <select id="dd" name="instroageStatus" style="width:120px;height:25px;">   
						      <option value="1">有库存</option>
						      <option value="2">全 &nbsp;部</option>
						 </select>
                    </td>
                    <td width="72">
                        <a id="search_btn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'">搜索</a>
                    </td>
                    <td width="72">
                        <a id="reset_btn" href="#" class="easyui-linkbutton" onclick="reloaddata()" data-options="iconCls:'icon-refresh'">重置</a>
                    </td>
                    <td width="0"></td>
                </tr>
                </tbody>
            </table>
            <input type="hidden" id="menuCode" value="100001001">
        </form>
    </div>
</div>
<div id="list"  style="display: none;"></div>
<div id="productList" class="easyui-datagrid">

</div>
</body>
</html>